﻿using MySql.Data.MySqlClient;
using System;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Text;

namespace ZHDJ.Data.Models.Common
{
    public class KeyWord : EntityBaseOperation
    {
        #region 属性

        /// <summary>
        /// 关键词
        /// </summary>
        [Required, StringLength(128)]
        public string WordText { get; set; }

        /// <summary>
        /// 描述
        /// </summary>
        [StringLength(256)]
        public string Description { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public int AlarmLevel { get; set; }
        #endregion

        /// <summary>
        /// 判断是否有敏感词
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public static bool IsContainSensitiveWords(string content)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(@"select WordText from tblKeyWord");

            DataTable dt = MySqlHelper.ExecuteDataTable(sb.ToString());

            foreach(DataRow dr in dt.Rows)
            {
                if(content.Contains(Convert.ToString(dr["WordText"])))
                {
                    return false;
                }
            }

            return true;
        }

        
    }
}
